package com.henghai.zhenxuan.domain.request;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

import com.henghai.zhenxuan.data.api.AppListApi;
import com.henghai.zhenxuan.data.bean.HttpBean;
import com.henghai.zhenxuan.data.bean.ProductBean;
import com.henghai.zhenxuan.data.repository.DataRepository;
import com.kunminx.architecture.data.response.DataResult;
import com.kunminx.architecture.domain.message.MutableResult;
import com.kunminx.architecture.domain.message.Result;
import com.kunminx.architecture.domain.request.Requester;

import org.jetbrains.annotations.NotNull;

public class AppListRequester extends Requester implements DefaultLifecycleObserver {


    private final MutableResult<DataResult<HttpBean<ProductBean>>> appListResult = new MutableResult<>();

    public Result<DataResult<HttpBean<ProductBean>>> getAppListResult() {
        return appListResult;
    }

    public void request(LifecycleOwner lifecycleOwner, String productType, String conversionType) {
        DataRepository.getInstance().appList(lifecycleOwner, new AppListApi(productType, conversionType), appListResult::postValue);
    }

    public void request(LifecycleOwner lifecycleOwner, String productType, String conversionType, String productName) {
        DataRepository.getInstance().appList(lifecycleOwner, new AppListApi(productType, conversionType, productName), appListResult::postValue);
    }

    public void cancelLogin() {

    }


    @Override
    public void onStop(@NonNull @NotNull LifecycleOwner owner) {
        cancelLogin();
    }

}
